AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')

function ENT:Use(activator, caller)
	if !caller:GetNWBool("Snipe Shieldd") then
		self.BaseClass.Use(self, activator, caller)
	end
end

function ENT:GiveItemEffects(ply)
	ply:SetNWBool("Snipe Shieldd", true)
end

local function Shield(ply, inflictor, attacker, ammount, dmginfo)
	if !ply:IsPlayer() then return end
	local attacker = dmginfo:GetAttacker()
	if ply:GetNWBool("Snipe Shieldd") then
		if dmginfo:GetDamage() >= math.Round(ply:Health() + ply:Armor()) then
			dmginfo:SetDamage(0)
			ply:SetNWBool("Snipe Shieldd", false)
			ply:SetHealth(1)
			ply:Armor(0)
			Notify(ply, 4, 3, "Snipe shield activated!")
			ply:EmitSound("HUDQuickInfo.LowHealth")
			if attacker:IsPlayer() && attacker != ply then
				Notify(attacker, 4, 3, "Target survived using snipe shield!")
			end
		end
	end
end
hook.Add("EntityTakeDamage", "Shield", Shield)

function UnShield(ply)
	ply:SetNWBool("Snipe Shieldd", false)
end
hook.Add("PlayerDeath", "Shield", UnShield)